#ifndef KMYSPRITE_H
#define KMYSPRITE_H

#include "../KmyStructDef.h"
#include "../KmySpriteTypedef.h"
#include "../KmyImagePak.h"
#include "KmyWorldComponent.h"
#include "../KmySpriteTemplate.h"

class KmyICanvas;

/** 精灵暂不支持旋转 */
class KmySprite : public KmyWorldComponent
{
public:
    KmySprite();
    KmySprite(KmySpriteTemplate* st);
    virtual ~KmySprite();

    void initialize();
    void finalize();

    KmySpriteTemplate* sprite_template;
    //----------Variable Data begin----------
    int z;
    int speed_x;
    int speed_y;

    int cur_anime_index;
    int cur_frame_index;

    const static int ANIMATION_STATE_STOP = 0;
    const static int ANIMATION_STATE_PLAY = 1;
    const static int ANIMATION_STATE_LOOP = 2;

    int animation_state;

    bool visible;
    bool enable;

    int getFlip();
    float getAngle();
    float getAlpha();
    void setFlip(int flip);
    void setAngle(float a);
    void setAlpha(float a);

    //----------Data end-----------------
    virtual void getActiveRange(St_Rect &range);
    void setAnime(int index);
    void setAnimeByName(string &aname);
    void setFrame(int index);
    bool nextFrame();
    void nextCycFrame();
    void setPosition(int x, int y, int z);

    int getNodeType();
    void logic();
    void render(KmyICanvas *screen);

//    void render(KmyICanvas *screen, St_Rect* camera);

    bool isInCamera(St_Rect *camera);

    bool isInScreen(KmyICanvas *screen);
private:
    // 最大范围
    St_Rect max_range;

    int flip;
    float angle;
    float alpha;
};

#endif // KMYSPRITE_H
